package sort;

import java.util.*;

public class leetcode {
    public static int majorityElement(int[] nums) {
        HashMap<Integer,Integer> map = new HashMap<Integer, Integer>();
        for (int i : nums){
            if (!map.containsKey(i)){
                map.put(i,1);
            }else {
                map.put(i,map.get(i) + 1);
                if (map.get(i) > nums.length/2){
                    return i;
                }
            }
        }
        return -1;
    }



    public static void main(String[] args) {
        String[] strs = {"flower","flow","flight"};


        int[] nums = {2,2,1,1,1,2,2};
        int res = majorityElement(nums);
        System.out.println();
    }
}
